home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 83win / data1.cab / Basic_Plus_Examples / BARMTRLM < prev    next >
Encoding:
Text File  |  2001-03-02  |  10.9 KB  |  288 lines

  1. 10    ! ******************************************************************
  2. 20    ! Example: Bar/Meter/Limits
  3. 30    !
  4. 40    ! This program demonstrates the use of the BAR, METER, and LIMITS
  5. 50    ! widgets.
  6. 60    !
  7. 70    ! The program creates three widgets and sets them up and down through
  8. 80    ! their default range of 1 through 100. You can set the LOW LIMIT
  9. 90    ! and HIGH LIMIT thresholds on both the widgets using a pair of SLIDER
  10. 100    ! widgets. As the program passes through the thresholds, it changes
  11. 110    ! the color and string on a LABEL via use of events.
  12. 120    !
  13. 130    ! The program sets up the widgets, sets up events on the SLIDERS and
  14. 140    ! BAR (no event is set up on other widgets, since the method is the
  15. 150    ! same), and then goes through a loop from 1 to 100 and then back
  16. 160    ! down again, changing the widgets with each count.
  17. 170    !
  18. 180    ! A routine called "Lobound" handles the SLIDER that sets the lower
  19. 190    ! trip limit, a routine called "Hibound" that handles the LIMIT that
  20. 200    ! sets the higher trip limit, and a routine called "Trip" that handles
  21. 210    ! the BAR events.
  22. 220    !
  23. 230    ! Some features of this program are:
  24. 240    !
  25. 250    !  - The program will NOT allow you to set the HIGH LIMIT below the
  26. 260    !    LOW LIMIT, or the inverse. Try to scroll into these regions and
  27. 270    !    the slidebar will pop back.
  28. 280    !
  29. 290    !  - Normally a BAR event is "level sensitive": if you set an event
  30. 300    !    to happen on the "HIGH" ALARM RANGE, you get an event each and
  31. 310    !    every time you write a value to that range. For this program,
  32. 320    !    however, an event occurs only on transition between ALARM RANGEs.
  33. 330    !
  34. 340    ! *******************************************************************
  35. 350   !
  36. 360    ! Variables used:
  37. 370   !
  38. 380    !   N:            Loop counter
  39. 390    !   Hibound:      Stores METER HIGH LIMIT
  40. 400    !   Lobound:      Stores METER LOW LIMIT
  41. 410    !   Sts:          Used to RETURN items from widgets
  42. 420   !
  43. 430       INTEGER N,Hibound,Lobound,Sts
  44. 440       Hibound=100
  45. 450       Lobound=1
  46. 460   !
  47. 470   ! Define colors
  48. 480   !
  49. 490       INTEGER Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
  50. 500       DATA 0,1,2,3,4,5,6,7
  51. 510       READ Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
  52. 520   !
  53. 530   ! Declare variables for display handling
  54. 540   !
  55. 550       INTEGER D(1:4),Dw,Dh,Cursor
  56. 560       INTEGER Pw,Ph,Px,Py,Iw,Ih,Gx,Gy
  57. 570       INTEGER Mx,My,Mh,Mw,Brx,Bry,Brh,Brw
  58. 580       INTEGER Lmx,Lmy,Lmh,Lmw,Lx,Ly,Lh,Lw
  59. 590       INTEGER Lshx,Lshy,Lshw,Lshh,S2x,S2y,S2w,S2h
  60. 600       INTEGER Lslx,Lsly,Lslw,Lslh,Slx,Sly,Slw,Slh
  61. 610   !
  62. 620   ! Get display dimensions
  63. 630   !
  64. 640       GESCAPE CRT,3;D(*)
  65. 650       Dw=D(3)-D(1)
  66. 660       Dh=D(4)-D(2)
  67. 670   !
  68. 680   ! Set up PANEL dimensions, so that PANEL scales to display
  69. 690   !
  70. 700       Pw=Dw*.8   ! PANEL width
  71. 710       Ph=Dh*.9   ! PANEL height
  72. 720       Px=(Dw-Pw)/2! Center PANEL along width
  73. 730       Py=(Dh-Ph)/2! Center PANEL above DISP line
  74. 740   !
  75. 750   ! Build main PANEL
  76. 760   !
  77. 770       CLEAR SCREEN
  78. 780   !
  79. 790       ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
  80. 800       CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
  81. 810       CONTROL @Main;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
  82. 820       CONTROL @Main;SET ("TITLE":" Example: Bar Meter Limits")
  83. 830       CONTROL @Main;SET ("SYSTEM MENU":"Quit")
  84. 840   !
  85. 850   ! Get interior dimensions of PANEL
  86. 860   !
  87. 870       STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
  88. 880   !
  89. 890   ! Set up widget dimensions
  90. 900   !
  91. 910       Gx=Iw*.02       ! Gap between widgets
  92. 920       Gy=Gx
  93. 930   !
  94. 940       Mw=Iw*.45       ! METER parameters
  95. 950       Mh=Ih*.5
  96. 960       Mx=Gx
  97. 970       My=Gy
  98. 980   !
  99. 990       Brw=(Iw-(Mw+2*Gx))*.3! BAR parameters
  100. 1000       Brh=Mh
  101. 1010       Brx=Mx+Mw+Gx
  102. 1020       Bry=My
  103. 1030  !
  104. 1040       Lmw=Mw+Gy+Brw ! LIMITS parameters
  105. 1050       Lmh=Ih-(Mh+3*Gy)
  106. 1060       Lmx=Gx
  107. 1070       Lmy=My+Mh+Gy
  108. 1080  !
  109. 1090       Lw=Iw-(Mw+Brw+4*Gy)! Indicator LABEL parameters
  110. 1100       Lh=Lw*.5
  111. 1110       Lx=Iw-(Lw+Gx)
  112. 1120       Ly=Gy
  113. 1130  !
  114. 1140       Lshw=(Lw-Gy)/2! High limit LABEL
  115. 1150       Lshh=Lshw*.4
  116. 1160       Lshx=Lx
  117. 1170       Lshy=Ly+Lh+Gy
  118. 1180  !
  119. 1190       Shw=Lshw      ! High limit SLIDER
  120. 1200       Shh=(Ih-(4*Gy+Lh+Lshh))
  121. 1210       Shx=Lx
  122. 1220       Shy=Lshy+Lshh+Gy
  123. 1230  !
  124. 1240       Lslw=Lshw     ! Low limit LABEL
  125. 1250       Lslh=Lshh
  126. 1260       Lslx=Lshx+Lshw+Gx
  127. 1270       Lsly=Lshy
  128. 1280  !
  129. 1290       Slw=Shw       ! Low limit SLIDER
  130. 1300       Slh=Shh
  131. 1310       Slx=Lslx
  132. 1320       Sly=Shy
  133. 1330  !
  134. 1340  ! Build rest of PANEL
  135. 1350  !
  136. 1360  ! Create METER. (There is no need to set ALL these
  137. 1370  ! attributes, but this is an example program).
  138. 1380  !
  139. 1390  ! The three METER ranges are assigned as red, white and blue -
  140. 1400  ! an arbitrary choice.
  141. 1410  !
  142. 1420       ASSIGN @Meter TO WIDGET "METER";PARENT @Main
  143. 1430       CONTROL @Meter;SET ("X":Mx,"Y":My,"WIDTH":Mw,"HEIGHT":Mh)
  144. 1440       CONTROL @Meter;SET ("HIGH PEN":Red,"MIDDLE PEN":White,"LOW PEN":Blue)
  145. 1450       CONTROL @Meter;SET ("VALUE BACKGROUND":Yellow,"VALUE PEN":Black)
  146. 1460       CONTROL @Meter;SET ("LIMITS BACKGROUND":Blue,"LIMITS PEN":White)
  147. 1470       CONTROL @Meter;SET ("NEEDLE PEN":Blue,"METER BACKGROUND":Green)
  148. 1480       CONTROL @Meter;SET ("SWEEP ANGLE":175)
  149. 1490  !
  150. 1500  ! Create BAR. Basically the same, but not as many options.
  151. 1510  !
  152. 1520       ASSIGN @Bar TO WIDGET "BAR";PARENT @Main
  153. 1530       CONTROL @Bar;SET ("X":Brx,"Y":Bry,"WIDTH":Brw,"HEIGHT":Brh)
  154. 1540       CONTROL @Bar;SET ("HIGH PEN":Red,"MIDDLE PEN":White,"LOW PEN":Blue)
  155. 1550  !
  156. 1560  ! Create LIMITS
  157. 1570  !
  158. 1580       ASSIGN @Lim TO WIDGET "LIMITS";PARENT @Main
  159. 1590       CONTROL @Lim;SET ("X":Lmx,"Y":Lmy,"WIDTH":Lmw,"HEIGHT":Lmh)
  160. 1600       CONTROL @Lim;SET ("INSIDE PEN":White,"OUTSIDE PEN":Magenta)
  161. 1610  !
  162. 1620  ! Create LABEL to indicate METER range
  163. 1630  !
  164. 1640       ASSIGN @Label TO WIDGET "LABEL";PARENT @Main
  165. 1650       CONTROL @Label;SET ("X":Lx,"Y":Ly,"WIDTH":Lw,"HEIGHT":Lh)
  166. 1660       CONTROL @Label;SET ("BORDER":0,"BACKGROUND":White,"VALUE":"NORM")
  167. 1670  !
  168. 1680  ! Create LABEL for HIGH LIMIT SLIDER
  169. 1690  !
  170. 1700       ASSIGN @Lsh TO WIDGET "LABEL";PARENT @Main
  171. 1710       CONTROL @Lsh;SET ("X":Lshx,"Y":Lshy,"WIDTH":Lshw,"HEIGHT":Lshh)
  172. 1720       CONTROL @Lsh;SET ("VALUE":"High")
  173. 1730  !
  174. 1740  ! Create SLIDER to set HIGH LIMIT
  175. 1750  !
  176. 1760       ASSIGN @Sh TO WIDGET "SLIDER";PARENT @Main
  177. 1770       CONTROL @Sh;SET ("X":Shx,"Y":Shy,"WIDTH":Shw,"HEIGHT":Shh)
  178. 1780       CONTROL @Sh;SET ("DIRECT MOVE":1,"AUTO REPEAT":1)
  179. 1790       CONTROL @Sh;SET ("VALUE":100)
  180. 1800  !
  181. 1810  ! Create LABEL for LOW LIMIT SLIDER
  182. 1820  !
  183. 1830       ASSIGN @Lsl TO WIDGET "LABEL";PARENT @Main
  184. 1840       CONTROL @Lsl;SET ("X":Lslx,"Y":Lsly,"WIDTH":Lslw,"HEIGHT":Lslh)
  185. 1850       CONTROL @Lsl;SET ("VALUE":"Low")
  186. 1860  !
  187. 1870  ! Create SLIDER to set LOW LIMIT
  188. 1880  !
  189. 1890       ASSIGN @Sl TO WIDGET "SLIDER";PARENT @Main
  190. 1900       CONTROL @Sl;SET ("X":Slx,"Y":Sly,"WIDTH":Slw,"HEIGHT":Slh)
  191. 1910       CONTROL @Sl;SET ("DIRECT MOVE":1,"AUTO REPEAT":1)
  192. 1920  !
  193. 1930  ! Call bounds handlers to set up initial bounds, then
  194. 1940  ! make main PANEL visible. (The bounds handlers will
  195. 1950  ! both call the "Trip" routine to initialize the BAR event.)
  196. 1960  !
  197. 1970       GOSUB Hibound
  198. 1980       GOSUB Lobound
  199. 1990       CONTROL @Main;SET ("VISIBLE":1)
  200. 2000  !
  201. 2010  ! Set up the event handlers
  202. 2020  !
  203. 2030       N=1
  204. 2040       ON EVENT @Sl,"DONE" GOSUB Lobound! Event for LOW LIMIT SLIDER
  205. 2050       ON EVENT @Sh,"DONE" GOSUB Hibound! Event for HI LIMIT SLIDER
  206. 2060       ON EVENT @Bar,"ALARM" GOSUB Trip! Event for BAR
  207. 2070       ON EVENT @Main,"SYSTEM MENU" GOTO Finis! Event for QUIT toaster menu
  208. 2080  !
  209. 2090  ! Count from 1 to 100 and back down, and set METER and
  210. 2100  ! BAR as this is done.
  211. 2110  !
  212. 2120       LOOP
  213. 2130           FOR N=1 TO 100
  214. 2140               CONTROL @Meter;SET ("VALUE":N)
  215. 2150               CONTROL @Bar;SET ("VALUE":N)
  216. 2160               CONTROL @Lim;SET ("VALUE":N)
  217. 2170           NEXT N
  218. 2180           FOR N=100 TO 1 STEP -1
  219. 2190               CONTROL @Meter;SET ("VALUE":N)
  220. 2200               CONTROL @Bar;SET ("VALUE":N)
  221. 2210               CONTROL @Lim;SET ("VALUE":N)
  222. 2220           NEXT N
  223. 2230       END LOOP
  224. 2240  !
  225. 2250  ! ********************* End of Main Program ************************
  226. 2260  !
  227. 2270  ! Handler for LOW LIMIT SLIDER:
  228. 2280  !
  229. 2290  Lobound:!
  230. 2300       DISABLE
  231. 2310       STATUS @Sl;RETURN ("VALUE":Lobound)! Get SLIDER VALUE
  232. 2320       IF Lobound>Hibound THEN         ! If higher than HIGH LIMIT:
  233. 2330           Lobound=Hibound             ! Make sure it is not
  234. 2340           CONTROL @Sl;SET ("VALUE":Lobound)
  235. 2350       END IF
  236. 2360       CONTROL @Meter;SET ("LOW LIMIT":Lobound)! Set limit on widgets
  237. 2370       CONTROL @Bar;SET ("LOW LIMIT":Lobound)
  238. 2380       CONTROL @Lim;SET ("LOW LIMIT":Lobound)
  239. 2390       GOSUB Trip                      ! Adjust BAR event handling
  240. 2400       ENABLE
  241. 2410       RETURN
  242. 2420  !
  243. 2430  ! HIGH LIMIT SCROLL BAR event handler
  244. 2440  !
  245. 2450  Hibound:!
  246. 2460       DISABLE
  247. 2470       STATUS @Sh;RETURN ("VALUE":Hibound)! Get SLIDER VALUE
  248. 2480       IF Hibound<Lobound THEN         ! If HIGH LIMIT < LOW LIMIT:
  249. 2490           Hibound=Lobound             ! Make sure it is not
  250. 2500           CONTROL @Sh;SET ("VALUE":Hibound)
  251. 2510       END IF
  252. 2520       CONTROL @Meter;SET ("HIGH LIMIT":Hibound)! Reflect on METER & LIMITS
  253. 2530       CONTROL @Bar;SET ("HIGH LIMIT":Hibound)
  254. 2540       CONTROL @Lim;SET ("HIGH LIMIT":Hibound)
  255. 2550       GOSUB Trip! Adjust event handling
  256. 2560       ENABLE
  257. 2570       RETURN
  258. 2580  !
  259. 2590  ! BAR event handler.
  260. 2600  ! You get the current value being sent to the BAR and determine
  261. 2610  ! the range it is in. Then, you set the event to occur on the
  262. 2620  ! adjoining range(s). This ensures that you only get an event when
  263. 2630  ! you transition between ranges.
  264. 2640  !
  265. 2650  ! As noted, the bounds handlers call Trip to adjust events. Since
  266. 2660  ! you are changing the HIGH & LOW LIMITs with the bounds handlers,
  267. 2670  ! you want to make sure that the events are rearranged accordingly.
  268. 2680  !
  269. 2690  Trip:!
  270. 2700       DISABLE
  271. 2710       SELECT N
  272. 2720       CASE <Lobound
  273. 2730           CONTROL @Bar;SET ("ALARM RANGES":"MIDDLE","ALARM TYPE":"EVENT")
  274. 2740           CONTROL @Label;SET ("BACKGROUND":Blue,"VALUE":"LOW")
  275. 2750       CASE <=Hibound
  276. 2760           CONTROL @Bar;SET ("ALARM RANGES":"LOW,HIGH","ALARM TYPE":"EVENT")
  277. 2770           CONTROL @Label;SET ("BACKGROUND":White,"VALUE":"NORM")
  278. 2780       CASE >Hibound
  279. 2790           CONTROL @Bar;SET ("ALARM RANGES":"MIDDLE","ALARM TYPE":"EVENT")
  280. 2800           CONTROL @Label;SET ("BACKGROUND":Red,"VALUE":"HIGH")
  281. 2810       END SELECT
  282. 2820       ENABLE
  283. 2830       RETURN
  284. 2840  !
  285. 2850  Finis:!
  286. 2860       ASSIGN @Main TO *! Delete PANEL widget
  287. 2870       END
  288.